package com.cjl.demo.test;

/**
 * <p>Copyright: All Rights Reserved</p>
 * <p>Description: 给定一个排序数组，你需要在原地删除重复出现的元素，使得每个元素只出现一次，返回移除后数组的新长度。
 不要使用额外的数组空间，你必须在原地修改输入数组并在使用 O(1) 额外空间的条件下完成。</p>
 *
 * @ uthor chenjinliang
 * @ date: 2019/1/16
 */
public class ArrayDemo {
    public static int removeDuplicates(int[] nums) {
        int result = 0;
        if(null != nums){
            for(int i =1; i<nums.length; i ++){
                if(nums[result] != nums[i]){
                    result++;
                    nums[result] = nums[i];
                }
            }
        }
        return result++;
    }

    public static void main(String[] args) {
        int[] nums = {1,1,2,3,3,10};
        int t = test(nums);
        System.out.println("nums = [" + t + "]");
    }

    public static int test(int[] inputArray){
        if(null == inputArray || inputArray.length <=1){
            return -1;
        }
        int max = 0;
        int index= 0;
        int next = 0;
        if(inputArray[0] > inputArray[1]){
            max = inputArray[0];
            next = inputArray[1];
        }else{
            max = inputArray[1];
            next = inputArray[0];
        }
        for(int i =2 ; i < inputArray.length; i ++){
            if(inputArray[i] < max && inputArray[i] > next){
                next = inputArray[i];
            }
            if(inputArray[i]> max){
                int tmp = max;
                max = inputArray[i];
                index = i;
                System.out.println("max = [" + max + "]" + " , next = " + next);
            }


        }
        System.out.println("111111111111max = [" + max + "]" + " , next = " + next);
        if(max > 3 * next){
            return index;
        }else{
            return -1;
        }
    }

}
